#include <Game\Include\Player.h>


Player::Player(const int &player_id, Ball* player_ball, Paddle* player_paddle)
{
    this->id = player_id;
    this->ball =  player_ball;
    this->paddle = player_paddle;
    this->score = 0;
    this->balls_available = INITIAL_BALLS_COUNT;
    this->blocks_taken_count = 0;

    this->move_left = false;
    this->move_right = false;
}

Player::~Player(void)
{
    // does not delete nothing.
}

Ball* Player::getBall()
{
    return this->ball;
}

Paddle* Player::getPaddle()
{
    return this->paddle;
}

void Player::moveRight()
{
    this->move_right = true;
    this->updateMovement();
}

void Player::stopMovingRight()
{
    this->move_right = false;
    this->updateMovement();
}

void Player::moveLeft()
{
    this->move_left = true;
    this->updateMovement();
}

void Player::stopMovingLeft()
{
    this->move_left = false;
    this->updateMovement();
}

void Player::updateMovement()
{
    if (this->move_left && this->move_right)
    {
        this->paddle->setMovementType(Paddle::PaddleMovementType::STATIC);
    }
    else if(this->move_left)
    {
        this->paddle->setMovementType(Paddle::PaddleMovementType::LEFT);
    }
    else if ( this->move_right )
    {
        this->paddle->setMovementType(Paddle::PaddleMovementType::RIGHT);
    }
    else
    {
        this->paddle->setMovementType(Paddle::PaddleMovementType::STATIC);
    }
}

Ball* Player::loseBall()
{
    Ball* old_ball = this->ball;
    this->ball = 0;
    this->balls_available -= 1;
    return old_ball;
}

void Player::setNewBall(Ball* ball)
{
    this->ball = ball;
}

void Player::tookBlock()
{
    this->score += 10;
    this->blocks_taken_count += 1;
}

int Player::getBallsAvailable()
{
    return this->balls_available;
}

int Player::getBlocksTaken()
{
    return this->blocks_taken_count;
}

int Player::getScore()
{
    return this->score;
}
